package util;

import com.deepoove.poi.XWPFTemplate;
import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

@Component
@RequiredArgsConstructor
public class PoiUtil {
//    private final MinioService minioService;
    /**
     *
     * @param render
     * @return
     * @throws Exception
     */
    public  String print(XWPFTemplate render) throws Exception {
        ByteArrayInputStream input = null;
        ByteArrayOutputStream outPDF = null;
        PdfOptions options = PdfOptions.create();
        try {
            outPDF = new ByteArrayOutputStream();
            PdfConverter.getInstance().convert(render.getXWPFDocument(), outPDF, options);
            input = new ByteArrayInputStream(outPDF.toByteArray());
//            String path = minioService.putObject("default", IdUtil.simpleUUID() + ".pdf", input);
            return "";
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (outPDF != null) {
                outPDF.close();//关闭BufferedOutputStream输出流
            }
            if (input != null) {
                input.close();//关闭input输出流
            }
        }
        return null;
    }

}
